from django.db import models
from utils.model_base import ModelBase

# Create your models here.

class UserMobileAndPwd(ModelBase):

    mobile = models.CharField(verbose_name='手机号', null=False, unique=True, max_length=20)
    password = models.CharField(verbose_name='密码', null=False, max_length=20)

    class Meta:
        db_table = 'user_and_pwd'
        verbose_name = '用户名和密码'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.mobile


class Company(ModelBase):
    """
    公司表
    """
    name = models.CharField(verbose_name='公司名称', null=False, max_length=100)
    company_id = models.CharField(verbose_name='公司id', null=False, max_length=20)

    class Meta:
        db_table = 'tb_company'
        verbose_name = '公司'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Monitor(ModelBase):
    """
    监控表
    """
    users = models.ForeignKey('UserMobileAndPwd', on_delete=models.CASCADE)
    companys = models.ForeignKey('Company', on_delete=models.CASCADE)

    class Meta:
        db_table = 'tb_monitor'
        verbose_name = '风险监控'
        verbose_name_plural = verbose_name

    def __str__(self):
        return '{}_{}'.format(self.users, self.companys)